package com.ltba.rf.control.file;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class AppDataManager {

	private static final String DATA_PATH = "./data/appdata.dat";

	public static AppData getAppdata() {
		try {
			ObjectInputStream in = new ObjectInputStream(new FileInputStream(
					DATA_PATH));
			return (AppData) in.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new AppData(0, 0, 0);
	}

	public static void saveAppData(AppData data) {
		ObjectOutputStream out = null;
		FileOutputStream fo = null;
		try {
			fo = new FileOutputStream(DATA_PATH);
			out = new ObjectOutputStream(fo);
			out.writeObject(data);
			fo.flush();
			fo.close();
			out.close();
		} catch (Exception e) {
			fo = null;
			out = null;
		}
	}
}
